﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xant.FlowEngine.Interface;
using Xant.OrganzService;
using Xunit;

namespace Xant.OrganzService.Tests
{
    public class Tester
    {

        [Fact]
        public void TestFindOrganization()
        {
            IOrganizationLocator locator = new OrganizationLocator();
            var dept = locator.FindOrganization(Guid.Parse("00000001-0000-0000-0000-000000000000"));
            Assert.Equal(dept.Name, "建筑集团有限公司");
            Assert.Equal(dept.Type, OrganizType.Corporation);
            dept = locator.FindOrganization(Guid.Parse("00000001-0001-0000-0000-000000000000"));
            Assert.Equal(dept.Name, "人事部");
            Assert.Equal(dept.Type, OrganizType.Department);
            dept = locator.FindOrganization(Guid.Parse("00000001-0101-0000-0000-000000000000"));
            Assert.Equal(dept.Name, "华东区");
            Assert.Equal(dept.Type, OrganizType.Fictitious);
        }

        [Fact]
        public void TestFindOrganizationNotLazy()
        {
            IOrganizationLocator locator = new OrganizationLocator(false);
            var dept1 = locator.FindOrganization(Guid.Parse("00000001-0102-0001-0000-000000000000"));
            Assert.Equal(dept1.Name, "广州公司");
            Assert.Equal(dept1.Type, OrganizType.Corporation);
            var dept2 = locator.FindOrganization(Guid.Parse("00000001-0102-0001-0001-000000000000"));
            Assert.Equal(dept2.Name, "人事部");
            Assert.Equal(dept2.Type, OrganizType.Department);
            var dept3 = locator.FindOrganization(Guid.Parse("00000001-0101-0000-0000-000000000000"));
            Assert.Equal(dept3.Name, "华东区");
            Assert.Equal(dept3.Type, OrganizType.Fictitious);
            Assert.Equal(dept2.Superior, dept1);
            Assert.Equal(dept1.Superior.Superior, dept3.Superior);
        }

        [Fact]
        public void TestOrganization()
        {
            var locator = new OrganizationLocator();
            Assert.Equal(locator.RootOrganizations.Count(), 2);
            var organz = locator.RootOrganizations.First();
            Assert.Equal(organz.Name, "建筑集团有限公司");
            Assert.Equal(organz.Subordinations.Count(), 5);
            Assert.Equal(organz.Subordinations.First().Name, "人事部");
            Assert.Equal(organz.Subordinations.Last().Name, "华南区");
            Assert.Equal(organz.StaffMembers.Count(), 4);
            var member = organz.StaffMembers.First();
            Assert.Equal(member.Staff.Name, "张无忌");
            Assert.Equal(member.Position.Name, "公司领导");
        }

        [Fact]
        public void Test()
        {
            string s1 = "Test";
            string s2 = "Test";
            Assert.True(Object.Equals(s1, s2));
            Position p1 = new Position() { Code = "Manager" };
            Position p2 = Xant.Utils.ObjectCloner.Clone(p1);
            Assert.Equal(p1, p2);
            Assert.True(p1 == p2);
        }
    }
}
